package org.aaron.demos;

import org.aaron.demos.bc.TestMyBroadcastReceiver;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Broadcast2Activity extends Activity{
	private Button unbundle_broadcast_btn,bundle_broadcast_btn;
	private TestMyBroadcastReceiver broadcastReceiver;
	private static final String SMS_RECEIVER_ACTION="android.provider.Telephony.SMS_RECEIVED";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.broadcast2layout);
		initActivity();
	}
	private void initActivity(){
		unbundle_broadcast_btn= (Button) this.findViewById(R.id.unbundle_broadcast_btn);
		unbundle_broadcast_btn.setOnClickListener(new UnBundleBroadcastClickListener());
		bundle_broadcast_btn= (Button) this.findViewById(R.id.bundle_broadcast_btn);
		bundle_broadcast_btn.setOnClickListener(new BundleBroadcastClickListener());
	}
	class BundleBroadcastClickListener implements OnClickListener{
		
		@Override
		public void onClick(View v) {
			broadcastReceiver=new TestMyBroadcastReceiver();
			IntentFilter filter=new IntentFilter();
			filter.addAction(SMS_RECEIVER_ACTION);
			Broadcast2Activity.this.registerReceiver(broadcastReceiver, filter);
			Log.d("Broadcast2Activity", "BundleBroadcastClickListener");
		}
	}
	class UnBundleBroadcastClickListener implements OnClickListener{
		
		@Override
		public void onClick(View v) {
			Broadcast2Activity.this.unregisterReceiver(broadcastReceiver);
			Log.d("Broadcast2Activity", "UnBundleBroadcastClickListener");
		}
	}
}
